<?php

namespace App\Utils\Logic\gao;

use App\Models\FangPublish;
use App\Utils\Lib\Redis;

/**
 * 推荐喜欢
 */
class LikeLogic
{
    public static function recommend($uid){

        $redis = Redis::createRedisObject();
        $redis->select(1);

        //从redis获取用户浏览信息
        $browseHistory = $redis->sMembers('browse_history_'.$uid);

        //从redis获取用户购买信息
        $purchaseHistory = $redis->sMembers('purchase_history_'.$uid);
        if (!$purchaseHistory) $purchaseHistory = [];

        //从redis获取用户收藏信息
        $collectionHistory = $redis->sMembers('collection_history_'.$uid);

        //合并数组 过滤空数组 过滤重复内容
        $recommendHotId = array_unique(array_filter(array_merge($browseHistory,$purchaseHistory,$collectionHistory)));

        $fangList = FangPublish::fangList(['id'=>$recommendHotId]);
        return $fangList;
    }
}
